var ClubMemberItem = Item.extend({
    _ccsFileName: res.ClubMemberItem1_json,
    _memberSettingCallBack: null,
    _userData: null,
    _clubId: null,
    initItem: function (idx, clubId, data) {
        this._userData = data;
        this._clubId = clubId;
    },


    onEnter: function () {
        Item.prototype.onEnter.call(this);
        this._addClickListeners();
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_operation': '_clickOperation',
        }
    },

    _clickOperation: function () {
        showWindow('ClubMemberSettingWindow', this._clubId, this._userData);
    },

    refreshData: function (idx, clubId, data) {
        this._userData = data;
        this._clubId = clubId;
        var stateObj = this._getUserState();
        var statusObj = this._getUserStatus();

        this._nodeList['idx'].setString(idx);
        this._nodeList['lb_name'].setString(ellipsisStr(this._userData['name'], ClubDataManager.NirckNameSize));
        this._nodeList['lb_id'].setString('ID:' + this._userData['uid']);

        this._nodeList['lb_groupName'].setString(this._userData['groupName'] || '未分组');
        this._nodeList['lb_states'].setString(stateObj.state);
        this._nodeList['lb_states'].setTextColor(stateObj.color);
        this._nodeList['lb_shenfen'].setString(statusObj.status);
        this._nodeList['lb_shenfen'].setTextColor(statusObj.color);
        this._nodeList['btn_operation'].setVisible(statusObj.operationVisible);
        loadImageToSprite(this._userData['headUrl'], this._nodeList['head']);
    },

    /**
     * 获取成员状态
     * @returns {{state: string, color: (cc.Color|Object)}}
     * @private
     */
    _getUserState: function () {
        var state = '离线';
        var color = cc.color(115, 115, 115);

        if (this._userData['state'] == 1) {
            state = '在线';
            color = cc.color(39, 182, 49);
        }
        if (this._userData['state'] == 2) {
            state = '游戏中';
            color = cc.color(255, 10, 10);
        }

        if (this._userData.black) {
            state = '禁玩';
            color = cc.color(255, 10, 10);
        }
        return {state: state, color: color};
    },

    /**
     * 获取成身份
     * @private
     */
    _getUserStatus: function () {
        var status = '成员';
        var operationVisible = true;
        var color = cc.color(214, 131, 43);
        if (this._userData['owner']) {
            status = '创建者';
            color = cc.color(214, 131, 43);
            operationVisible = false;
        }
        else if(this._userData['partner']){
            status = '合伙人';
            operationVisible = false;
            color = cc.color(214, 131, 43);
        } else if (this._userData['admins']) {
            status = '管理员';
            operationVisible = false;
            color = cc.color(214, 131, 43);
        }
        //群主 指定显示操作按钮
        if(this._userData['partner']) {
            operationVisible = false;
        }else if (!this._userData['owner'] && gameData.uid == ClubDataManager.getClubData(this._clubId).owner_uid) {
            operationVisible = true;
        } else if (!ClubDataManager.getClubUidIsAdmin(this._clubId, gameData.uid)) {
            operationVisible = false;
        }
        return {status: status, color: color, operationVisible: operationVisible};
    },
});